package com.xiebishe.mylibrary.common.pageStatus.topHandler;

import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;

public class LinearLayoutTopHandler extends TopStatusHandler<LinearLayout> {


    public LinearLayoutTopHandler(@NonNull LinearLayout layout, int centerInTopPx) {
        super(layout, centerInTopPx);
    }


    @Override
    protected void removeView(@NonNull View view, @NonNull LinearLayout layout) {
        layout.removeView(view);
    }

    @Override
    protected boolean onHideContent(@NonNull LinearLayout layout) {
        setAllGone(layout);
        return true;
    }

    @Override
    protected boolean onShowContent(@NonNull LinearLayout layout) {
        restoreLastVisibility(layout);
        return true;
    }

    @Override
    protected void addToTop(@NonNull View view, @NonNull LinearLayout layout, int centerInTopPx) {
        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        if (layoutParams != null) {
            layout.addView(view);
        } else {
            LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, centerInTopPx);
            layout.addView(view, layoutParams1);
        }
    }
}
